from flask import Blueprint, render_template, request, jsonify
from models import MonitoringTask, MonitoredVideo, Comment, MonitoredVideoHistory
from utils.DataVisualization import VisualizationTool
import pandas as pd
from model.emotionAnalysisDir_DLUT.emotion_analysis_dlut import EmotionAnalysisDLUT
from model.bert_cold_model.bert_cold_model import BertTextClassifier as cold_bert
from model.bert_sarcasm_model.bert_sarcasm_model import BertTextClassifier as sarcasm_bert

model_use_bp = Blueprint("model_use", __name__, url_prefix="/model_use")


@model_use_bp.route("/")
def views():
    return render_template('model_test.html')


@model_use_bp.route("/test", methods=['POST'])
def test():
    # 获取传入的参数
    model = request.form.get('model')
    text = request.form.get('text')
    topic = request.form.get('topic')
    result = 0
    if model == 'dlut_emotion_dict':
        result = use_DLUT_dic(text)
    elif model == 'bert_cold_model':
        result = use_cold_bert(text)
    else:
        result = use_sarcasm_bert(topic, text)
    # 返回 JSON 响应
    return jsonify({"result": result})


def use_DLUT_dic(text):
    return EmotionAnalysisDLUT().classify_text(text)


def use_cold_bert(text):
    return cold_bert.predict(text)


def use_sarcasm_bert(topic, text):
    return sarcasm_bert.predict(topic, text)
